/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Manufacture")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Manufacture.findAll", query = "SELECT m FROM Manufacture m"),
    @NamedQuery(name = "Manufacture.findByResource", query = "SELECT m FROM Manufacture m WHERE m.manufacturePK.resource = :resource"),
    @NamedQuery(name = "Manufacture.findByFactory", query = "SELECT m FROM Manufacture m WHERE m.manufacturePK.factory = :factory"),
    @NamedQuery(name = "Manufacture.findByAmount", query = "SELECT m FROM Manufacture m WHERE m.amount = :amount")})
public class Manufacture implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ManufacturePK manufacturePK;
    @Column(name = "amount")
    private Integer amount;
    @JoinColumn(name = "factory", referencedColumnName = "building", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Factory factory1;
    @JoinColumn(name = "resource", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Resource resource1;

    public Manufacture() {
    }

    public Manufacture(ManufacturePK manufacturePK) {
        this.manufacturePK = manufacturePK;
    }

    public Manufacture(int resource, int factory) {
        this.manufacturePK = new ManufacturePK(resource, factory);
    }

    public ManufacturePK getManufacturePK() {
        return manufacturePK;
    }

    public void setManufacturePK(ManufacturePK manufacturePK) {
        this.manufacturePK = manufacturePK;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Factory getFactory1() {
        return factory1;
    }

    public void setFactory1(Factory factory1) {
        this.factory1 = factory1;
    }

    public Resource getResource1() {
        return resource1;
    }

    public void setResource1(Resource resource1) {
        this.resource1 = resource1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (manufacturePK != null ? manufacturePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Manufacture)) {
            return false;
        }
        Manufacture other = (Manufacture) object;
        if ((this.manufacturePK == null && other.manufacturePK != null) || (this.manufacturePK != null && !this.manufacturePK.equals(other.manufacturePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Manufacture[ manufacturePK=" + manufacturePK + " ]";
    }
    
}
